package controller

import (
	"github.com/gofiber/fiber/v2"
	"guns-excel/internal/app/model"
	"guns-excel/internal/app/service"
	"guns-excel/internal/pkg/util/result"
)

// 新增
func AddRule(ctx *fiber.Ctx) error {
	rule := new(model.Rule)
	if err := ctx.BodyParser(rule); err != nil {
		return ctx.JSON(result.Err.WithMsg("解析参数出错，请检查传参"))
	}
	if err := service.AddRule(ctx, rule); err != nil {
		return ctx.JSON(result.Err.WithMsg("新增失败"))
	}
	return ctx.JSON(result.OK)
}

// 根据模型获取字段
func GetRuleByModelExcelId(ctx *fiber.Ctx) error {
	modelExcelId := ctx.Query("modelExcelId")
	rule, err := service.GetRuleByModelExcelId(ctx, modelExcelId)
	if err != nil {
		return err
	}
	return ctx.JSON(result.OK.WithData(rule))
}
